<template>
  <div class="func-comp-form">

    <ComponentGlobalSettingForm :id="id" :compConfigData="compConfigData"></ComponentGlobalSettingForm>

    <Tabs name="main_tabs" size="small" v-model="mainTabsValue">
      <TabPane name="main_tab" tab="main_tabs" label="主配置">

        <Tabs name="main_tabs_child" size="small">
          <TabPane tab="main_tabs_child" label="基础配置">
            <Collapse value="0">
              <Panel>
                常规配置
                <div slot="content">
                  <EchartsGridConfigForm v-model="chartOption.grid"></EchartsGridConfigForm>
                </div>
              </Panel>
              <Panel>
                x轴
                <ShowToggle class="float-right" v-model="chartOption.xAxis.show"></ShowToggle>
                <div slot="content">
                  <EchartsXAxisConfigForm v-model="chartOption.xAxis"></EchartsXAxisConfigForm>
                </div>
              </Panel>
              <Panel>
                y轴
                <ShowToggle class="float-right" v-model="chartOption.yAxis.show"></ShowToggle>
                <div slot="content">
                  <EchartsYAxisConfigForm v-model="chartOption.yAxis"></EchartsYAxisConfigForm>
                </div>
              </Panel>
              <Panel>
                提示框
                <ShowToggle class="float-right" v-model="chartOption.tooltip.show"></ShowToggle>
                <div slot="content">
                  <EchartsTooltipConfigForm v-model="chartOption.tooltip"></EchartsTooltipConfigForm>
                </div>
              </Panel>
              <Panel>
                图例
                <ShowToggle class="float-right" v-model="chartOption.legend.show"></ShowToggle>
                <div slot="content">
                  <EchartsLegendConfigForm v-model="chartOption.legend"></EchartsLegendConfigForm>
                </div>
              </Panel>
              <Panel v-if="chartOption.title">
                标题
                <ShowToggle class="float-right" v-model="chartOption.title.show"></ShowToggle>
                <div slot="content">
                  <EchartsTitleConfigForm v-model="chartOption.title"></EchartsTitleConfigForm>
                </div>
              </Panel>
              <Panel>
                视觉映射
                <div slot="content">
                  <EchartsVisualMapConfigForm v-model="chartOption"></EchartsVisualMapConfigForm>
                </div>
              </Panel>
              <Panel>
                其他
                <div slot="content">
                  <EchartsOtherConfigForm v-model="compConfigData"></EchartsOtherConfigForm>
                </div>
              </Panel>
            </Collapse>
          </TabPane>
          <TabPane tab="main_tabs_child" label="系列映射">
            <Button class="float-right" size="small" type="primary" @click="addSeries"><Icon type="md-add" /> 新增系列</Button>
            <div class="clearfix"></div>
            <div class="m-b-10px"></div>

            <draggable tag="Collapse" :component-data="{attrs: {accordion: true}}" :list="chartOption.series" handle=".ivu-collapse-header">
              <Panel :name="$PnUtil.uuid()" v-for="(row, index) in chartOption.series" :key="index">
                {{row.name ? row.name : '系列' + (index + 1)}}
                <a href="javascript:;" class="float-right m-r-5px" style="color: #757575;" @click.stop="deleteSeries(index)"><Icon type="md-trash" /></a>
                <div slot="content">
                  <Form :label-width="100">
                    <FormItem label="系列名">
                      <Input size="small" v-model="row.name" placeholder=""/>
                    </FormItem>

                    <Tabs size="small">
                      <TabPane label="基本样式">
                        <FormItem label="柱条宽度">
                          <Tooltip content="柱条的宽度，不设时自适应，可以是绝对值例如 40 或者百分数例如 '60%'" max-width="200" placement="left">
                            <Input size="small" v-model="row.barWidth" placeholder="默认自适应"/>
                          </Tooltip>
                        </FormItem>
                        <FormItem label="异系列柱间距">
                          <Tooltip content="不同系列的柱间距离，为百分比（如 '30%'，表示柱子宽度的 30%）" max-width="200" placement="left">
                            <Input size="small" v-model="row.barGap"/>
                          </Tooltip>
                        </FormItem>
                        <FormItem label="同系列柱间距">
                          <Tooltip content="同一系列的柱间距离，默认为类目间距的20%，可设固定值" max-width="200" placement="left">
                            <Input size="small" v-model="row.barCategoryGap"/>
                          </Tooltip>
                        </FormItem>

                        <Collapse class="m-t-5px" value="0">
                          <Panel>
                            柱条样式
                            <div slot="content">
                              <FormItem label="颜色">
                                <Tooltip content="设置颜色，将会覆盖渐变色设置" placement="left">
                                  <PnColorPicker size="small" v-model="row.itemStyle.color" alpha recommend/>
                                </Tooltip>
                              </FormItem>
                              <FormItemPanel title="渐变色">
                                <FormItem label="起始颜色">
                                  <PnColorPicker size="small" v-model="row.itemStyle.startColor" alpha recommend/>
                                </FormItem>
                                <FormItem label="结束颜色">
                                  <PnColorPicker size="small" v-model="row.itemStyle.endColor" alpha recommend/>
                                </FormItem>
                              </FormItemPanel>
                              <FormItem label="边框宽度">
                                <InputNumber size="small" :max="1000" :min="0" v-model="row.itemStyle.borderWidth"></InputNumber>
                              </FormItem>
                              <FormItem label="边框颜色">
                                <PnColorPicker size="small" v-model="row.itemStyle.borderColor" alpha recommend/>
                              </FormItem>
                              <FormItem label="边框类型">
                                <Select :transfer="true" size="small" v-model="row.itemStyle.borderType">
                                  <Option v-for="(item, index) in $PnChartDict.borderStyles" :value="item.value" :key="index">{{ item.label }}</Option>
                                </Select>
                              </FormItem>
                              <FormItem label="圆角半径">
                                <InputNumber size="small" :max="1000" :min="0" v-model="row.itemStyle.barBorderRadius" :active-change="false"></InputNumber>
                              </FormItem>
                              <FormItem label="阴影大小">
                                <InputNumber size="small" :max="1000" :min="0" v-model="row.itemStyle.shadowBlur" :active-change="false"></InputNumber>
                              </FormItem>
                              <FormItem label="阴影颜色">
                                <PnColorPicker size="small" v-model="row.itemStyle.shadowColor" alpha recommend/>
                              </FormItem>
                            </div>
                          </Panel>
                          <Panel>
                            柱条背景
                            <ShowToggle class="float-right" v-model="row.showBackground"></ShowToggle>
                            <div slot="content">
                              <FormItem label="颜色">
                                <PnColorPicker size="small" v-model="row.backgroundStyle.color" alpha recommend/>
                              </FormItem>
                              <FormItem label="边框宽度">
                                <InputNumber size="small" :max="1000" :min="0" v-model="row.backgroundStyle.borderWidth" :active-change="false"></InputNumber>
                              </FormItem>
                              <FormItem label="边框颜色">
                                <PnColorPicker size="small" v-model="row.backgroundStyle.borderColor" alpha recommend/>
                              </FormItem>
                              <FormItem label="边框类型">
                                <Select :transfer="true" size="small" v-model="row.backgroundStyle.borderType">
                                  <Option v-for="(item, index) in $PnChartDict.borderStyles" :value="item.value" :key="index">{{ item.label }}</Option>
                                </Select>
                              </FormItem>
                              <FormItem label="边框圆角">
                                <InputNumber size="small" :max="1000" :min="0" v-model="row.backgroundStyle.borderRadius" :active-change="false"></InputNumber>
                              </FormItem>
                              <FormItem label="阴影大小">
                                <InputNumber size="small" :max="1000" :min="0" v-model="row.backgroundStyle.shadowBlur" :active-change="false"></InputNumber>
                              </FormItem>
                              <FormItem label="阴影颜色">
                                <PnColorPicker size="small" v-model="row.backgroundStyle.shadowColor" alpha recommend/>
                              </FormItem>
                            </div>
                          </Panel>
                          <Panel>
                            值标签
                            <ShowToggle class="float-right" v-model="row.label.show"></ShowToggle>
                            <div slot="content">
                              <FormItem label="位置">
                                <Select :transfer="true" size="small" v-model="row.label.position">
                                  <Option v-for="item in $PnChartDict.positions" :value="item.value" :key="item.value">{{ item.label }}</Option>
                                </Select>
                              </FormItem>
                              <FormItem label="旋转角度">
                                <InputNumber size="small" :max="360" :min="0" v-model="row.label.rotate" :active-change="false"></InputNumber>
                              </FormItem>
                              <FormItem label="格式化">
                                <Input size="small" v-model="row.label.formatter"/>
                              </FormItem>
                              <FormItem label="颜色">
                                <PnColorPicker size="small" v-model="row.label.color" alpha recommend/>
                              </FormItem>
                              <FormItem label="字体大小">
                                <InputNumber size="small" :max="1000" :min="0" v-model="row.label.fontSize" :active-change="false"></InputNumber>
                              </FormItem>
                            </div>
                          </Panel>
                        </Collapse>
                      </TabPane>
                      <TabPane label="辅助线">
                        <EchartsMarkLineConfigForm v-model="row.markLine"></EchartsMarkLineConfigForm>
                      </TabPane>
                      <TabPane label="标注">
                        <EchartsMarkPointConfigForm v-model="row.markPoint"></EchartsMarkPointConfigForm>
                      </TabPane>
                    </Tabs>

                  </Form>
                </div>
              </Panel>
            </draggable>
          </TabPane>
        </Tabs>

      </TabPane>
      <TabPane name="extend_tab" tab="main_tabs" label="扩展配置">
        <Container v-if="mainTabsValue == 'extend_tab'">
          <CustomOptionDocument :componentId="id" :customOption="customOption" :showDataZoomConfigBtn="true"></CustomOptionDocument>
          <CodeEditor v-model="customOption"></CodeEditor>
          <EchartsSpreadingCodeForm v-model="echartsSpreadingCode"></EchartsSpreadingCodeForm>
        </Container>
      </TabPane>
      <TabPane name="datasource_tab" tab="main_tabs" label="数据源">
        <DatasourceState v-if="mainTabsValue == 'datasource_tab'" targetComp="BaseBarChart"></DatasourceState>
      </TabPane>
      <TabPane name="interaction_tab" tab="main_tabs" label="交互">
        <Container v-if="mainTabsValue == 'interaction_tab'">
          <InteractionReceive></InteractionReceive>
          <CustomJsDocument></CustomJsDocument>
          <FormItemPanel title="初始化运行脚本">
            <CodeEditor v-model="customGlobalJsCode"></CodeEditor>
          </FormItemPanel>

          <FormItemPanel title="数据项点击时运行">
            <InteractionSender :interactionKey="'itemClick'"></InteractionSender>
            <Alert style="padding: 5px;">此脚本中，使用_this指向当前组件vm实例，通过params可获取点击项数据</Alert>
            <CodeEditor v-model="dataItemClickJsCode"></CodeEditor>
          </FormItemPanel>
        </Container>
      </TabPane>
    </Tabs>
  </div>
</template>

<script>

  import FuncCompFormMixin from '@/mixin/FuncCompFormMixin'

  import BaseBarChart from './BaseBarChart'

  import { createHelpers } from 'vuex-map-fields';

  const { mapFields } = createHelpers({
    getterType: 'designer/getLayoutItem',
    mutationType: 'designer/updateLayoutItem',
  });

  export default {
    name: 'BaseBarChartForm',
    mixins: [FuncCompFormMixin],
    data() {
      return {

      }
    },
    mounted() {
    },
    methods: {
      addSeries () {
        this.chartOption.series.push(BaseBarChart.buildSeriesObj(''))
      },
      deleteSeries (index) {
        this.chartOption.series.splice(index, 1)
      }
    },
    computed: {
      ...mapFields({

        chartOption: 'component.compConfigData.chartOption'

      })
    }
  }
</script>

<style scoped>

</style>
